

Ext.onReady(function(){
    Ext.QuickTips.init();

		var tb = Ext.create('Ext.toolbar.Toolbar');
		tb.suspendLayout = true;
		tb.render('toolbar');	
		tb.add(
				{	
				text:'<b>GESTOR</b>',
				iconCls: 'icon-alpha',				
				menu: 	Ext.create('Ext.menu.Menu', {										        
						items: [	{   text: '<b>ADMINISTRACION</b>', iconCls: 'icon-adm', itemId: 'adminis', hidden: true,
										menu: [	{text: '<b>USUARIOS</b>',iconCls: 'icon-user',itemId: 'admUsuarios', hidden: true, handler: function(){ window.location = "usuarios";}},
												{text: '<b>ROLES</b>',iconCls: 'icon-rol',itemId: 'admRoles', hidden: true, handler: function(){ window.location = "roles";}},
												{text: '<b>PROYECTOS</b>',iconCls: 'icon-proyecto', hidden: true,itemId: 'admProyectos', handler: function(){ window.location = "proyectos";}}]		
									},
									{   text: '<b>PROYECTOS</b>', iconCls: 'blist', iconCls: 'icon-proyect', itemId: 'proyec', hidden: true,
										menu: [	{text: '<b>CONFIGURACION</b>',iconCls: 'icon-conf', hidden: true, itemId: 'idConf' , handler: function(){ window.location = "configuracion"; }},
												{text: '<b>GESTION CONFIG</b>',iconCls: 'icon-gestion', itemId: 'idGestion', hidden: true, handler: function(){ window.location = "gestionConf";}},
												{text: '<b>DESARROLLO</b>', iconCls: 'icon-desarrollo', hidden: true,  itemId: 'idDesarrollo', handler: function(){ window.location = "desarrollo";}}]		
									}													
						]
					}) 
			},{
				text:'<b>INFO</b>',
				iconCls: 'icon-alpha',
				menu: [	{text: '<b>PERFIL</b>',iconCls: 'icon-perfil', handler: function(){ window.location = "perfil";}},
						{text: '<b>ACERCA DE</b>',iconCls: 'information',handler: function(){
							win = Ext.create('widget.window', {
							title: 'ALPHA MANAGER',
							iconCls: 'icon-alpha',
							closable: true,
							width: 450,
							minWidth: 350,
							height: 300,
							layout: 'border',

							items: [ {
								region: 'center',
								xtype: 'tabpanel',
								items: [{
									title: 'Autores',
									html: ' <h2>- Carlos Aquino <br> - Adolfo Martinez <br> - Santiago Vera</h2>'
								}, {
									title: 'Descripcion',
									html: '<h2>Gestor de Proyectos</h2>'
								}]
							}]
						});
					
					win.show();} }]
			}
			
			
		);
					
    	function getPermisos()
		{
			Ext.Ajax.request({
					url: 'listarPermisos_Logueado',
					method: 'GET',
					success: function(response) {
						var jsonData = Ext.JSON.decode(response.responseText);
						var resultMessage = jsonData['data'];
						if(extraer(resultMessage,'{','adm-')){	
							tb.down('#adminis').show();							
						}
						if(extraer(resultMessage,'{adm-','usuario')){	
							tb.down('#admUsuarios').show();
						}
						if(extraer(resultMessage,'{adm-','rol') || extraer(resultMessage,'{adm','permiso')){	
							tb.down('#admRoles').show();
						}
						if(extraer(resultMessage,'{adm-','proyecto')){	
							tb.down('#admProyectos').show();
						}
						if(extraer(resultMessage,'{','conf-')|| extraer(resultMessage,'{','des-') || extraer(resultMessage,'{','ges-')){	
							tb.down('#proyec').show();							
						}
						if(extraer(resultMessage,'{','conf-')){	
							tb.down('#idConf').show();
						}
						if(extraer(resultMessage,'{','des-')){
							tb.down('#idDesarrollo').show();							
						}												
						if(extraer(resultMessage,'{','ges-')){	
							tb.down('#idGestion').show();							
						}
						
					}
			});
		}
		getPermisos();
   
});

function extraer(texto, etqini, etqfin){
		var ind0, ind1, parte ="";
		ind0 = texto.indexOf(etqini);
		if (ind0 >=0){
			ind1 = texto.indexOf(etqfin);
			if (ind1>ind0)
				parte = texto.substring(ind0+etqini.length, ind1);
		}
		return parte;
}
